<!--
 * @Description: 物流跟踪表
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:53:17
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px;" class="el-icon-arrow-down"></i>
              </span>
              <span v-show="showCardNav">
                <i style="margin-right: 5px;" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="margin-bottom:10px;display: inline-block;">
                  <span style="margin-right: 12px;">车牌号：</span>
                  <el-input v-model="searchForm.carNo" style="width: 220px;" placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px;">
                  <span style="margin-right: 12px;">状态：</span>
                  <el-select v-model="searchForm.dataStatus" placeholder="请选择">
                    <el-option label="检测中" value="1"></el-option>
                    <el-option label="运输中" value="2"></el-option>
                    <el-option label="浇筑中" value="3"></el-option>
                    <el-option label="已签收" value="4"></el-option>
                    <el-option label="未确认" value="5"></el-option>
                    <el-option label="待签收" value="6"></el-option>
                    <el-option label="已拒绝" value="7"></el-option>
                    <el-option label="已取消" value="8"></el-option>
                    <el-option label="已完成" value="9"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParams.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="card">
            <div v-loading="tableLoading" class="card_info">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index) in table">
                  <el-table-column v-if="item.status" :key="index" :label="item.label" align="center" :width="item.width">
                    <template slot-scope="scope">
                      <div v-if="item.label == '计划浇筑方式'">
                        <div v-if="scope.row.pouringMethodSplit">
                          {{ scope.row.pouringMethodSplit[scope.row.pouringMethodSplit.length - 1] == ',' ? 
                            scope.row.pouringMethodSplit.substring(0,scope.row.pouringMethodSplit.length - 1) :
                            scope.row.pouringMethodSplit }}
                          </div>
                      </div>
                      <div v-else-if="item.label == '状态'">
                        <div v-if="scope.row.dataStatus == 1">检验中</div>
                        <div v-if="scope.row.dataStatus == 2">运输中</div>
                        <div v-if="scope.row.dataStatus == 3">浇筑中</div>
                        <div v-if="scope.row.dataStatus == 4">已签收</div>
                        <div v-if="scope.row.dataStatus == 5">未确认</div>
                        <div v-if="scope.row.dataStatus == 6">待签收</div>
                        <div v-if="scope.row.dataStatus == 7">已拒绝</div>
                        <div v-if="scope.row.dataStatus == 8">已取消</div>
                        <div v-if="scope.row.dataStatus == 9">已完成</div>
                      </div>
                      <div v-else-if="item.label == '运输号'">
                        <span style="color: #008000; cursor: pointer;" @click="transportLook(scope.row)">{{ scope.row.code }}</span>
                      </div>
                      <div v-else-if="item.label == '运输数据来源'">
                        <div v-if="scope.row.dataType == 1">{{ scope.row.productionSite }} (ERP)</div>
                        <div v-if="scope.row.dataType == 2">信息补录</div>
                        <div v-if="scope.row.dataType == 3">空票签收</div>
                        <div v-if="scope.row.dataType == 4">
                          <div>外协数据</div>
                          <div v-if="scope.row.orderType != 3">
                            <el-radio-group v-model="scope.row.isProcessing" disabled>
                              <el-radio :label="1">直供</el-radio>
                              <el-radio :label="2">代加工</el-radio>
                            </el-radio-group>
                            <el-radio-group v-model="scope.row.isCarriage" disabled>
                              <el-radio :label="1">我方运输</el-radio>
                              <el-radio :label="2">外协运输</el-radio>
                            </el-radio-group>
                            <el-radio-group v-model="scope.row.isPumping" disabled>
                              <el-radio :label="1">我方泵送</el-radio>
                              <el-radio :label="2">外协泵送</el-radio>
                            </el-radio-group>
                          </div>
                          <div v-else>
                            <el-radio-group v-model="scope.row.isProcessing" disabled>
                              <el-radio :label="2">直供</el-radio>
                              <el-radio :label="1">代加工</el-radio>
                            </el-radio-group>
                            <el-radio-group v-model="scope.row.isCarriage" disabled>
                              <el-radio :label="2">我方运输</el-radio>
                              <el-radio :label="1">外协运输</el-radio>
                            </el-radio-group>
                            <el-radio-group v-model="scope.row.isPumping" disabled>
                              <el-radio :label="2">我方泵送</el-radio>
                              <el-radio :label="1">外协泵送</el-radio>
                            </el-radio-group>
                          </div>
                        </div>
                      </div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParams.page" :page-size="tableParams.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData()">刷新</el-button>
        </div>
      </div>
    </el-container>

    <!-- 运输查看 -->
    <TransportLookDialog :config="TransportLookConfig" :visible.sync="TransportLookVisible" />
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import { getUserInfo } from "@/utils/auth.js";
import { query_logistics_page } from "@/api/smart/schedul/d.js"
import TransportLookDialog from "./components/TransportLookDialog"
export default {
  mixins: [mixin],
  filters: {
    pouringMethodFilter(e) {
      if (e) {
        e = JSON.parse(e);
        let table = e.map((res) => res.name);
        let text = table.join("、");
        return text;
      }
    },
  },
  components: {
    TransportLookDialog,
  },
  data() {
    return {
      searchForm: {
        carNo: '', // 车牌号
        dataStatus: '', // 状态
      },
      tableLoading: false, // 表格加载
      tableParams: { // 表格页参数
        pageSize: 10,
        page: 1
      },
      total: 0, // 表格数据总条数
      table: [ // 表格数据结构
        { label: "运输号", width: "auto", prop: "orderNo", status: true },
        { label: "工程名称", width: "auto", prop: "engineeringName", status: true },
        { label: "浇筑部位", width: "auto", prop: "structuralParts", status: true },
        { label: "产品名称", width: "auto", prop: "productName", status: true },
        { label: "计划浇筑方式", width: "auto", prop: "pouringMethodSplit", status: true },
        { label: "生产站点", width: "auto", prop: "productionSite", status: true },
        { label: "车牌号", width: "auto", prop: "carNo", status: true },
        { label: "生产时间", width: "auto", prop: "proTime", status: true },
        { label: "票面量（方）", width: "auto", prop: "faceValue", status: true },
        { label: "生产量（方）", width: "auto", prop: "proNum", status: true },
        { label: "富余量（方）", width: "auto", prop: "residueNum", status: true },
        { label: "转入量", width: "auto", prop: "shiftTo", status: true },
        { label: "调整余斜量（方）", width: "auto", prop: "adjustResidueNum", status: true },
        { label: "调整签收量（方）", width: "auto", prop: "adjustSignForNum", status: true },
        { label: "运输数据来源", width: "auto", prop: "", status: true },
        { label: "状态", width: "auto", prop: "", status: true },
      ],
      tableData: [], // 表格数据

      TransportLookConfig: {},
      TransportLookVisible: false,
    };
  },
  async created() {
    this.UserInfo = await getUserInfo();
    this.gettableData();
  },
  methods: {
    async gettableData() { // 获取表格数据
      const params = {...this.searchForm, ...this.tableParams}
      const res = await query_logistics_page(params)
      if(res.code === 1001) {
        this.tableData = res.data.data;
        this.total = res.data.totalRows;
      }
    },
    init() { // 重置
      this.searchForm = { 
        carNo: '', // 车牌号
        dataStatus: '', // 状态
      }
      this.tableParams = { // 表格页参数
        pageSize: 10,
        page: 1
      }
      this.gettableData();
    },
    sizeChange(value) { // 选择显示条数
      this.tableParams.pageSize = value;
      this.gettableData();
    },
    transportLook(row) { // 运输查看，点击运输号
      this.TransportLookConfig = {
        id: row.id
      }
      this.TransportLookVisible = true
    }
  },
};
</script>
<style lang="scss" scoped></style>
